﻿using System.Linq;
using Dolany.UtilityTool;
using Missbot.Common;

namespace Missbot.AIModule.Pet
{
    /// <summary>
    /// 宠物等级服务
    /// </summary>
    public class PetLevelSvc : ISingleton, IDataMgr
    {
        private SafeDictionary<int, PetLevel> LevelDic;

        public PetLevel this[int level] => LevelDic[level];
        
        public void RefreshData()
        {
            LevelDic = PetLevelDA.GetAll().ToDictionary(p => p.Level, p => p).ToSafe();
        }
        
        /// <summary>
        /// 将经验折算成金币
        /// </summary>
        /// <param name="level"></param>
        /// <param name="exp"></param>
        /// <returns></returns>
        public int ExpToGolds(int level, int exp)
        {
            var petAssert = 0;
            for (var i = 1; i < level; i++)
            {
                petAssert += this[i].Exp * 10;
            }

            petAssert += exp * 10;
            return petAssert;
        }
    }
}